package cn.com.fssg.platform.base.handler.impl.cl.org;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import cn.com.fssg.platform.biz.BizUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ClOrgClockInHistoryInterfaceHandler implements InterfaceHandler {

//    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantJdbcTemplate("CJRLHHConnString");
    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        String dyqId = jsonObject.getString("dyqId");
        String sql = "SELECT * from cl_sign_record " +
                " where " +
                "  dyq_id =:dyqId and " +
                " (date >= date_trunc('month', current_date) and date < date_trunc('month', current_date) + interval '1 month')";
        Map<String, Object> parms = new HashMap<>();
        parms.put("dyqId", dyqId);
        try {
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, parms);
            return list;

        } catch (Exception e) {
            return "jdbc:" + jdbcTemplate + "; message:" + e.getMessage();
        }
    }
}
